home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
409_01
/
paranoid.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-21
|
24KB
|
852 lines
/****************************************************************************
*
* Paranoid - VESA VBE stress test program
*
* Copyright (C) 1993 SciTech Software.
* All rights reserved.
*
* Filename: $RCSfile: paranoid.c $
* Version: $Revision: 1.1 $
*
* Language: ANSI C
* Environment: IBM PC (MS DOS)
*
* Description: Paranoid test program. This program is designed to stress
* test a VESA VBE implementation, and check it for full
* conformance with the VBE standard that it claims to conform
* to (supports only standards >= 1.2 standard).
*
* This program uses the SuperVGA test kit to perform all
* graphics output when testing the appropriate video modes
* for conformance (and thus only works on 386 and above
* machines).
*
* MUST be compiled in the large memory model.
*
* This program is freely distributable in the executable
* form. The source code is under the same restrictions as
* the SuperVGA kit it belong in.
*
* $Id: paranoid.c 1.1 1993/10/22 08:59:44 kjb release $
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <dos.h>
#include <string.h>
#include <conio.h>
#include "svga.h"
#include "vesavbe.h"
/*----------------------------- Implementation ----------------------------*/
typedef struct {
int ax,bx,cx,dx,si,di,es,ds;
} regs;
FILE *logfile = NULL;
int CP_x,CP_y,VBEVersion,maxbanks,VBEFunc = 0,numErrors = 0;
bool failed = false;
short modelist[100];
char *signon = "Paranoid v1.0 - VESA VBE stress test program\n"
" Copyright (C) 1993 SciTech Software\n\n";
/* Table of memory model names */
char *memModelNames[] = {
"Text Mode",
"CGA Graphics",
"Hercules Graphics",
"4-plane planar",
"Packed Pixel",
"Non-chain 4, 256 color",
"Direct Color RGB",
"Direct Color YUV",
};
int queryCpu(void);
void out(const char *fmt, ... )
{
va_list argptr;
va_start(argptr, fmt);
vfprintf(stdout, fmt, argptr);
vfprintf(logfile, fmt, argptr);
va_end(argptr);
}
void log(const char *fmt, ... )
{
va_list argptr;
va_start(argptr, fmt);
vfprintf(logfile, fmt, argptr);
va_end(argptr);
}
/* Routine to convert the input value to its binary representation */
char *binary(unsigned value)
{
static char buf[11] = "00000000b";
unsigned mask = 0x80;
int i;
for (i = 0; i < 8; i++) {
buf[i] = value & mask ? '1' : '0';
mask >>= 1;
}
return buf;
}
void startCheck(int _VBEFunc)
/****************************************************************************
*
* Function: startCheck
* Parameters: _VBEFunc - VBE Function number we are currently checking
*
* Description: Begins the logging of errors for this function.
*
****************************************************************************/
{
log("Checking function %02Xh ... ", VBEFunc = _VBEFunc);
numErrors = 0;
}
void endCheck(void)
/****************************************************************************
*
* Function: endCheck
*
* Description: Ends the checking of a particular VBE function.
*
****************************************************************************/
{
if (numErrors == 0)
log("Passed.\n");
else
log("\n%d errors logged for function %02Xh.\n", numErrors, VBEFunc);
}
void fail(const char *msg, ... )
/****************************************************************************
*
* Function: fail
* Parameters: msg - Message describing error
*
* Description: Logs a failure message to the log file outlining the problem
* that was encountered.
*
****************************************************************************/
{
va_list argptr;
if (numErrors == 0)
log("\n\n");
numErrors++;
failed = true;
va_start(argptr, msg);
fprintf(logfile," ");
vfprintf(logfile, msg, argptr);
va_end(argptr);
}
bool callVBE(regs *r)
/****************************************************************************
*
* Function: callVBE
* Parameters: r - Structure holding register values to load
* Returns: True if successful, false if function failed
*
* Description: Loads the appropriate registers with the values from
* the register structure and executes and int 10h to call
* the VBE. It checks to ensure that register values are
* preserved across all calls correctly and ensures that the
* function executed successfully.
*
****************************************************************************/
{
union REGS rg;
struct SREGS sr;
int mask;
rg.x.ax = r->ax; rg.x.bx = r->bx;
rg.x.cx = r->cx; rg.x.dx = r->dx;
rg.x.si = r->si; rg.x.di = r->di;
sr.es = r->es; sr.ds = r->ds;
int86x(0x10,&rg,&rg,&sr);
/* Check to ensure all register are preserved across call. We define
* the mask to be a one for a register that must be preserved, and
* a zero for a register that can change. AX is always the result
* code, so this leave 7 bits to represent each register.
*/
switch (r->ax & 0xFF) {
case 0x00: mask = 0x7F; break;
case 0x01: mask = 0x7F; break;
case 0x02: mask = 0x7F; break;
case 0x03: mask = 0x7E; break;
case 0x04: if ((r->dx & 0xFF) == 0)
mask = 0x7E; /* State size call */
else mask = 0x7F; /* Other calls */
break;
case 0x05: if ((r->bx >> 8) == 0)
mask = 0x7F; /* Set window call */
else mask = 0x7B; /* Get window call */
break;
case 0x06: mask = 0x78; break;
case 0x07: if (r->bx == 0)
mask = 0x7F; /* Set display start */
else mask = 0x78; /* Get display start */
break;
case 0x08: mask = 0x7E; break;
default: mask = 0;
}
if ((mask & 0x01) && (r->bx != rg.x.bx))
fail("Function %02Xh failed to preserve BX\n", r->ax & 0xFF);
if ((mask & 0x02) && (r->cx != rg.x.cx))
fail("Function %02Xh failed to preserve CX\n", r->ax & 0xFF);
if ((mask & 0x04) && (r->dx != rg.x.dx))
fail("Function %02Xh failed to preserve DX\n", r->ax & 0xFF);
if (r->si != rg.x.si)
fail("Function %02Xh failed to preserve SI\n", r->ax & 0xFF);
if (r->di != rg.x.di)
fail("Function %02Xh failed to preserve DI\n", r->ax & 0xFF);
if (r->ds != sr.ds)
fail("Function %02Xh failed to preserve DS\n", r->ax & 0xFF);
if (r->es != sr.es)
fail("Function %02Xh failed to preserve ES\n", r->ax & 0xFF);
r->ax = rg.x.ax; r->bx = rg.x.bx;
r->cx = rg.x.cx; r->dx = rg.x.dx;
r->si = rg.x.si; r->di = rg.x.di;
r->es = sr.es; r->ds = sr.ds;
return (r->ax == 0x004F);
}
void checkFunction00h(void)
/****************************************************************************
*
* Function: checkFunction00h
*
* Description: Calls function 00h to determine if a VESA VBE is present,
* and check it for conformance.
*
****************************************************************************/
{
VgaInfoBlock vgaInfo;
regs r;
short i,*modes;
r.es = SEG(&vgaInfo);
r.di = OFF(&vgaInfo);
r.ax = 0x4F00;
if (callVBE(&r)) {
if (vgaInfo.VESAVersion < 0x102) {
out("Detected a VBE %d.%d interface. This program only checks interfaces that\n",
vgaInfo.VESAVersion >> 0x8,vgaInfo.VESAVersion & 0xF);
out("conform to the VBE 1.2 or later specifications.\n");
exit(1);
}
printf("VBE %d.%d Interface detected - checking for conformance\n\n",
vgaInfo.VESAVersion >> 0x8,vgaInfo.VESAVersion & 0xF);
log("VBE Version: %d.%d\n",vgaInfo.VESAVersion >> 0x8,
vgaInfo.VESAVersion & 0xF);
log("OEMString: %s\n",vgaInfo.OEMStringPtr);
log("Capabilities: %s (%04Xh)\n",binary(vgaInfo.Capabilities),
vgaInfo.Capabilities);
log("Total Memory: %d Kb\n",memory = vgaInfo.TotalMemory * 64);
log("\nAvailable Modes:\n\n");
modes = vgaInfo.VideoModePtr;
i = 0;
while (*modes != -1) {
modelist[i] = *modes;
log("%04Xh ",*modes++);
if ((++i % 10) == 0)
log("\n");
}
modelist[i] = -1;
log("\n\n");
startCheck(0x00);